<?php


namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;

class SwaggerController extends Controller
{

    /**
     * @OA\Info(
     *     description="Laravel-Shop商城API",
     *     version="1.0.0",
     *     title="Laravel-Shop商城API文档站点"
     * )
     * @OA\SecurityScheme(
     *     type="http",
     *     in="header",
     *     securityScheme="authorization",
     *     scheme="bearer",
     *     bearerFormat="JWT",
     *     name="authorization"
     * ),
     */
    public function index()
    {
        if (app()->environment() !== 'production') {//非生产环境

            $openapi = \OpenApi\scan(app_path('Http/Controllers') . '/Api');
//            return response()->json($openapi->toJson(),200);
//            header('Content-Type: application/json');
//            echo $openapi->toJson();
            return response($openapi->toYaml(), 200, [
                'Content-Type' => 'application/x-yaml'
            ]);
        } else {
            return response('', 404);
        }
    }
}
